package com.lee.config.interceptor;

import org.apache.kafka.clients.producer.ProducerInterceptor;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;

import java.util.Map;

/**
 * @Description TODO
 * @Author winston
 * @DateTime 2021/11/27
 */
public class CounterInterceptor implements ProducerInterceptor<String, String> {
	int success , error;
	@Override
	public ProducerRecord<String, String> onSend(ProducerRecord<String, String> record) {
		return record;
	}

	@Override
	public void onAcknowledgement(RecordMetadata metadata, Exception exception) {
		if (metadata != null) {
			success++;
		} else {
			error++;
		}
	}

	@Override
	public void close() {
		System.out.println(success);
		System.out.println(error);
	}

	@Override
	public void configure(Map<String, ?> configs) {

	}
}
